package models
{
	import events.URLEvent;
	
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;
	
	import vos.RSSItem;
	
	import mx.collections.ArrayCollection;
	
	public class FeedItemListPresentationModel extends EventDispatcher
	{
		private static const MODEL_CHANGE:String = "FeedItemListModelCHANGE";
		
		private var dispatcher:IEventDispatcher;
		private var _feedItemData:ArrayCollection;
		private var _feedTitle:String;
		private var _feedImage:String;
		
		public function FeedItemListPresentationModel(target:IEventDispatcher)
		{
			dispatcher = target;
			super(target);
		}
		
		[Bindable(event=MODEL_CHANGE)]
		public function get feedItemData():ArrayCollection
		{
			return _feedItemData;
		}
		
		public function set feedItemData(value:ArrayCollection):void
		{
			_feedItemData = value;
			dispatchEvent(new Event(MODEL_CHANGE));
		}
		
		[Bindable(event=MODEL_CHANGE)]
		public function get feedTitle():String
		{
			return _feedTitle;
		}
		
		public function set feedTitle(value:String):void
		{
			_feedTitle = value;
			dispatchEvent(new Event(MODEL_CHANGE));
		}
		
		[Bindable(event=MODEL_CHANGE)]
		public function get feedImage():String
		{
			return _feedImage;
		}
		
		public function set feedImage(value:String):void
		{
			_feedImage = value;
			dispatchEvent(new Event(MODEL_CHANGE));
		}
		
		public function openItem(item:RSSItem):void
		{
			if (item == null)
			{
				return;
			}
			
			var event:URLEvent = new URLEvent(URLEvent.OPEN);
			event.URL = item.link;
			item.read = true;
			dispatcher.dispatchEvent(event);
		}
	}
}